**********************************************************************************************************************************************************************
*Replication package for "Competition and Debt Conservatism"

*This file named "CompetitionZL_full_code.do" contains all codes that we used to (1) open and clean each dataset, (2) merge all datasets onto the global firms, (3) apply exclusion criteria and winsorize (thus arriving at the final sample), (4) and perform all empirical analysis on the final sample. Each section is bookmarked for easier navigation. Each section contains a brief description (in comments) to explain the logic and sequence of the data procedures. 

*The final sample (FinalSamplePseudo.dta) data, which is used for our regressions and analysis, cannot be shared publicly due to licensing restrictions. Hence, for the final sample, we prepared a randomized version of it for the codes to execute. As the pseudo final sample is not the actual sample used in the paper, the estimation results from the pseudo samples will not be the same as those reported in the paper. In the pseudo sample, we use "pseudo_id" to replace the actual firm identifiers (gvkey2). 

*For enquiries, please contact Woon Sau Leung (w.s.leung@soton.ac.uk).
**********************************************************************************************************************************************************************


*****************************************************
**# Set up the directory - use your local directories
*****************************************************
*This folder is the main folder containing all datasets and .do file
global directory "X:\xxx\xxx\"

*This temporary folder contains intermediate files for:
*Estimated ROA volatlities
global directory_qroavol "X:\xxx\xxx\qroavol\"
global directory_ZLEvent "X:\xxx\xxx\ZLEvent\"
global directory_stacked "X:\xxx\xxx\Stacked\"
global directory_stackedPSM "X:\xxx\xxx\StackedPSM\"

*This folder contains estimation outputs
global directory_results "X:\xxx\xxx\Results\"


********************************************
**# Variable construction - Compustat Global
********************************************
cd "$directory"
use CompustatGlobalFundamentalRaw1987_2021, clear

compress

gen date2=mofd(datadate)
format date2 %tm

label variable date2 "Monthly date"

*Merge to get end of month exchange rates for each currency; alternatively, one could use the exchange rates provided by Compustat Global.
cd "$directory"
merge m:1 curcd date2 using CurrencyDataMonthlyPanelReady
drop if _merge==2
drop _merge

*Renaming the variables - prefix "CG" refers to variable from Compustat Global
rename at CG_at
rename seq CG_seq
rename teq CG_teq
rename ceq CG_ceq
rename sale CG_sale
rename cogs CG_cogs
rename xsga CG_xsga
rename ppent CG_ppent
rename ib CG_ib
rename dp CG_dp
rename capx CG_capx
rename lt CG_lt
rename pstk CG_pstk
rename re CG_re
rename ebit CG_ebit
rename wcap CG_wcap
rename txditc CG_txditc
rename txt CG_txt
rename acctstd CG_acctstd
rename curcd CG_curcd
rename exchg CG_exchg
rename isin CG_isin
rename sedol CG_sedol
rename fic CG_fic
rename add1 CG_add1
rename add2 CG_add2
rename add3 CG_add3
rename add4 CG_add4
rename city CG_city
rename idbflag CG_idbflag
rename loc CG_loc
rename prican CG_prican
rename prirow CG_prirow
rename priusa CG_priusa
rename sic CG_sic
rename ipodate CG_ipodate
rename fyear CG_fyear
rename fyr CG_fyr
rename datadate CG_datadate
rename ggroup CG_ggroup 
rename gind CG_gind 
rename gsector CG_gsector 
rename gsubind CG_gsubind
rename naicsh CG_naicsh
rename act CG_act
rename lct CG_lct
rename aqc CG_aqc
rename nicon CG_nicon
rename dvc CG_dvc
rename dvp CG_dvp
rename emp CG_emp
rename xrd CG_xrd
rename cshr CG_cshr
rename che CG_che
rename oibdp CG_oibdp
rename revt CG_revt
rename dlc CG_dlc
rename dltt CG_dltt
rename dltr CG_dltr
rename dltis CG_dltis
rename prstkc CG_prstkc
rename sstk CG_sstk
rename xint CG_xint

*Monetary variables converted to USD
gen CG_at_usd=CG_at/DS_currency
gen CG_seq_usd=CG_seq/DS_currency
gen CG_teq_usd=CG_teq/DS_currency
gen CG_sale_usd=CG_sale/DS_currency
gen CG_cogs_usd=CG_cogs/DS_currency
gen CG_xsga_usd=CG_xsga/DS_currency

label variable CG_at_usd "Total assets in USD"
label variable CG_seq_usd "Total shareholder equity (seq) in USD"
label variable CG_teq_usd "Total shareholder equity (teq) in USD"
label variable CG_sale_usd "Total sales in USD"
label variable CG_cogs_usd "Total cost of goods sold in USD"
label variable CG_xsga_usd "Selling, general, adn admin expenses in USD"

gen gvkey2=real(gvkey)

*Remove duplicate within each gvkey-fyear
sort gvkey2 CG_fyear CG_datadate
by gvkey2 CG_fyear: gen dup=_n
drop if dup>1
drop dup

*Merge with monthly prices (it contains month-end prices, market cap, stock returns (in both local and USD), and cumulative returns (in both local and USD) over t to t-11 months) - constructed using the Compustat Global monthly security files)
merge m:1 gvkey2 date2 using CompustatGlobalMonthEndPricesReady1984_2021
drop if _merge==2
drop _merge


********************
*Construct variables
********************
*R&D - missing R&D treated as 0
replace CG_xrd=0 if CG_xrd==.
gen CG_RD_S=CG_xrd/CG_sale

label variable CG_RD_S "R&D/Total sales"

*Dividend variables
gen CG_DIV_A=CG_dvc/CG_at

label variable CG_DIV_A "Dividend/Total assets"

*Cash holdings
gen CG_CPA=CG_che/CG_at

label variable CG_CPA "Cash and short-term investments/Total assets"

*SG&A/TA
replace CG_xsga=0 if CG_xsga==.
gen CG_SGA_A=CG_xsga/CG_at
label variable CG_SGA_A "SG&A/Total assets; missing SG&A are treated as zero"

*ROA2
gen CG_ROA2=CG_oibdp/CG_at
label variable CG_ROA2 "Operating income before extraordinary items (oibdp)/Total assets"

*Asset tangibility
gen CG_PPE_A=CG_ppent/CG_at
label variable CG_PPE_A "Asset tangibility, computed as Net PPE (ppent)/Total assets"

*Investment/TA
gen CG_CAPX_A=CG_capx/CG_at
label variable CG_CAPX_A "Capital investment intensity, computed as CAPX (capx)/Total assets"

*Market to book equity ratio
gen CGD_MB=CGD_MV/CG_at if CG_curcd==CGD_curcd & CG_curcd!="USD"
replace CGD_MB=CGD_MV_usd/CG_at if CG_curcd=="USD"
replace CGD_MB=CGD_MV_usd/CG_at_usd if CG_curcd!=CGD_curcd & CGD_MB==.
gen CGD_lnMB=ln(CGD_MB)
label variable CGD_MB "market to book equity ratio; computed as Market capitalization (MV)/total assets"
label variable CGD_lnMB "ln(CGD_MB)"

*Firm size
gen CGD_lnMV=ln(CGD_MV)
gen CGD_lnMV_usd=ln(CGD_MV_usd)
gen CG_lnTA=ln(CG_at)
gen CG_lnTA_usd=ln(CG_at_usd)
gen CG_lnSALE=ln(CG_sale)
gen CG_lnSALE_usd=ln(CG_sale_usd)

label variable CGD_lnMV "ln(CGD_MV)"
label variable CGD_lnMV_usd "ln(CGD_MV_usd) USD"
label variable CG_lnTA "ln(CG_at)"
label variable CG_lnTA_usd "ln(CG_at_usd) in USD"
label variable CG_lnSALE "ln(CG_SALE)"
label variable CG_lnSALE_usd "ln(CG_SALE_usd) in USD"

*Finanical Leverage
egen DEBT=rowtotal(CG_dlc CG_dltt)
replace DEBT=. if CG_dlc==. & CG_dltt==.
gen CEQ_1=-1*CG_ceq
egen deno_leverage=rowtotal(CG_at CEQ_1 CGD_MV)

gen CG_LEV_A=DEBT/CG_at
gen CG_LEV_MV=DEBT/deno_leverage

label variable CG_LEV_A "Total debt/Total assets"

*Industry codes
gen CG_SIC4=real(CG_sic)
ffind CG_SIC4, newvar(CG_FF48) type(48)
ffind CG_SIC4, newvar(CG_FF12) type(12)
ffind CG_SIC4, newvar(CG_FF30) type(30)

label variable CG_SIC4 "4-digit SIC codes"
label variable CG_FF48 "FamaFrench 48 industries"
label variable CG_FF12 "FamaFrench 12 industries"
label variable CG_FF30 "FamaFrench 30 industries"

*Cash flow
egen CG_CF=rowtotal(CG_ib CG_dp)
replace CG_CF=. if CG_ib==.
gen CG_CF_A=CG_CF/CG_at

label variable CG_CF_A "Cash flow/TA"

*Tobin's q
gen TX=-1*CG_txditc
replace TX=0 if TX==.
replace CG_pstk=0 if CG_pstk==.

gen CG_MVA=(CGD_MV+CG_lt+CG_pstk-TX)
gen CG_DIFF=CG_at-CG_ppent

gen CG_Q_A=(CG_MVA-CG_DIFF)/CG_at

sort gvkey2 CG_fyear
by gvkey2: gen CG_Q_A2=(CG_MVA-CG_DIFF)/CG_at[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1

label variable CG_Q_A "Tobin's q; source: Investment-cash flow sensitivity cannot be a good measure of financial constraints: Evidence from the time series"

*Whited and Wu's (2006) financial-constraint index
gen CG_SIC2=int(CG_SIC4/100)
gen CG_cyear=year(CG_datadate)
egen DIV3=rowtotal(CG_dvc CG_dvp)
gen DIV3_D=1 if DIV3>0 & DIV3!=.
replace DIV3_D=0 if DIV3_D==. & DIV3!=.

sort gvkey2 CG_fyear
by gvkey2: gen CG_SALE_G=(CG_sale-CG_sale[_n-1])/CG_sale[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
bys CG_SIC2 CG_cyear: egen AVG_SALE_G=mean(CG_SALE_G)

gen CG_WW=-0.091*(CG_CF/CG_at)-0.062*DIV3_D+0.021*(CG_dltt/CG_at)-0.044*(log(CG_at))+0.102*AVG_SALE_G-0.035*CG_SALE_G

*Taxes and Non-debt tax shield
gen CG_TXT_A=CG_txt/CG_at
gen CG_NDTS_A=CG_dp/CG_at
replace CG_NDTS_A=0 if CG_NDTS_A==. & CG_at!=.

*Repurchase/TA
gen CG_REPUR_A=CG_prstkc/CG_at

*Total payout/TA
egen CG_TPAYOUT=rowtotal(CG_dvc CG_prstkc)
gen CG_TPAYOUT_A=CG_TPAYOUT/CG_at

*Equity issuance
egen CG_EIS=rowtotal(CG_sstk)
gen CG_EIS_A=CG_EIS/CG_at

*Keep the following variables to align between Compustat Global and CRSP/Compustat Merged
keep gvkey2 DS_currency CG_acctstd CG_curcd CG_fyear CG_fyr CG_datadate CG_act CG_aqc CG_at CG_capx CG_ceq CG_che CG_cogs CG_cshr CG_dlc CG_dltis CG_dltr CG_dltt CG_dp CG_dvc CG_dvp CG_ebit CG_emp CG_ib CG_lct CG_lt CG_oibdp CG_ppent CG_prstkc CG_pstk CG_re CG_revt CG_sale CG_seq CG_sstk CG_teq CG_txditc CG_txt CG_wcap CG_xrd CG_xsga CG_exchg CG_isin CG_sedol CG_nicon CG_fic CG_naicsh CG_add1 CG_add2 CG_add3 CG_add4 CG_city CG_ggroup CG_gind CG_gsector CG_gsubind CG_idbflag CG_loc CG_prican CG_prirow CG_priusa CG_sic CG_ipodate CG_at_usd CG_seq_usd CG_teq_usd CG_sale_usd CG_cogs_usd CG_xsga_usd CG_RD_S CG_DIV_A CG_CPA CG_ROA2 CG_PPE_A CG_CAPX_A CG_lnTA CG_lnTA_usd CG_lnSALE CG_lnSALE_usd CG_LEV_A CG_SIC4 CG_FF48 CG_FF12 CG_FF30 CG_CF CG_CF_A CG_PPE CG_Q_A CG_SIC2 CG_cyear CG_WW CG_TXT_A CG_NDTS_A CG_REPUR_A CG_TPAYOUT CG_TPAYOUT_A CGD_curcd CGD_prc CGD_prc_usd CGD_MV CGD_MV_usd CGD_cshocM CGD_ajexdi CGD_adjprc CGD_adjprc_usd CGD_MB CGD_lnMB CGD_lnMV CGD_lnMV_usd CG_xint CG_EIS_A CGD_ret12 CGD_ret12_usd CGD_ajexdi CGD_adjprc CGD_adjprc_usd CG_LEV_MV

order gvkey2 CG_fyear CG_cyear DS_currency CG_loc

sort gvkey2 CG_fyear
foreach var in CG_act CG_aqc CG_at CG_capx CG_ceq CG_che CG_cogs CG_cshr CG_dlc CG_dltis CG_dltr CG_dltt CG_dp CG_dvc CG_dvp CG_ebit CG_emp CG_ib CG_lct CG_lt CG_oibdp CG_ppent CG_prstkc CG_pstk CG_re CG_revt CG_sale CG_seq CG_sstk CG_teq CG_txditc CG_txt CG_wcap CG_xrd CG_xsga CG_nicon CG_at_usd CG_seq_usd CG_teq_usd CG_sale_usd CG_cogs_usd CG_xsga_usd CG_RD_S CG_DIV_A CG_CPA CG_ROA2 CG_PPE_A CG_CAPX_A CG_lnTA CG_lnTA_usd CG_lnSALE CG_lnSALE_usd CG_LEV_A CG_CF CG_CF_A CG_PPE CG_Q_A CG_WW CG_TXT_A CG_NDTS_A CG_REPUR_A CG_TPAYOUT CG_TPAYOUT_A CGD_prc CGD_prc_usd CGD_MV CGD_MV_usd CGD_cshocM CGD_adjprc CGD_adjprc_usd CGD_MB CGD_lnMB CGD_lnMV CGD_lnMV_usd CG_xint CG_EIS_A CGD_ret12 CGD_ret12_usd CGD_ajexdi CGD_adjprc CGD_adjprc_usd CG_LEV_MV {
capture by gvkey2: gen l1_`var'=`var'[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
label variable l1_`var' "one year lagged of `var'"
}

gen GLOBAL=1

label variable GLOBAL "1=Global; 0=US"

save CompustatGlobalReady, replace


**************************************************************
**# Variable Construction - Compustat-CRSP Merged Fundamentals
**************************************************************
cd "$directory"
use CompustatNAFundamentalRaw1987_2021, clear

rename *, lower

compress

gen gvkey2=real(gvkey)
drop gvkey

gen CG_cusip8=substr(cusip,1,8)

gen date2=mofd(datadate)
format date2 %tm

keep if fic=="USA" | fic=="CAN"

cd "$directory"
merge m:1 curcd date2 using CurrencyDataMonthlyPanelReady
drop if _merge==2
drop _merge

replace DS_currency=1 if curcd=="USD"
replace DS_currency=1 if fic=="USA" & curcd!="CAD"

*Remove duplicate within each gvkey2-fyear
sort gvkey2 fyear datadate
by gvkey2 fyear: gen dup=_n
drop if dup>1
drop dup

*Renaming
rename at CG_at
rename seq CG_seq
rename teq CG_teq
rename ceq CG_ceq
rename sale CG_sale
rename cogs CG_cogs
rename xsga CG_xsga
rename ppent CG_ppent
rename ib CG_ib
rename dp CG_dp
rename capx CG_capx
rename lt CG_lt
rename pstk CG_pstk
rename re CG_re
rename ebit CG_ebit
rename wcap CG_wcap
rename txditc CG_txditc
rename txt CG_txt
rename acctstd CG_acctstd
rename curcd CG_curcd
rename exchg CG_exchg
rename cusip CG_cusip
rename fic CG_fic
rename add1 CG_add1
rename add2 CG_add2
rename add3 CG_add3
rename add4 CG_add4
rename city CG_city
rename idbflag CG_idbflag
rename loc CG_loc
rename prican CG_prican
rename prirow CG_prirow
rename priusa CG_priusa
rename sic CG_sic
rename ipodate CG_ipodate
rename fyear CG_fyear
rename fyr CG_fyr
rename datadate CG_datadate
rename ggroup CG_ggroup 
rename gind CG_gind 
rename gsector CG_gsector 
rename gsubind CG_gsubind
rename naicsh CG_naicsh
rename naics CG_naics
rename act CG_act
rename lct CG_lct
rename aqc CG_aqc
rename ni CG_nicon
rename dvc CG_dvc
rename dvp CG_dvp
rename emp CG_emp
rename xrd CG_xrd
rename cshr CG_cshr
rename che CG_che
rename oibdp CG_oibdp
rename revt CG_revt
rename dlc CG_dlc
rename dltt CG_dltt
rename dltr CG_dltr
rename dltis CG_dltis
rename prstkc CG_prstkc
rename sstk CG_sstk
rename xint CG_xint

gen CG_at_usd=CG_at/DS_currency
gen CG_seq_usd=CG_seq/DS_currency
gen CG_teq_usd=CG_teq/DS_currency
gen CG_sale_usd=CG_sale/DS_currency
gen CG_cogs_usd=CG_cogs/DS_currency
gen CG_xsga_usd=CG_xsga/DS_currency

*Market capitalization
gen CGD_MV=(prcc_f*csho)
gen CGD_MV_usd=((prcc_f/DS_currency))*csho

gen CGD_lnMV=ln(CGD_MV)
gen CGD_lnMV_usd=ln(CGD_MV_usd)


********************
*Construct variables
********************
*R&D
replace CG_xrd=0 if CG_xrd==.
gen CG_RD_S=CG_xrd/CG_sale

*Dividend variables
gen CG_DIV_A=CG_dvc/CG_at

*Cash holdings
gen CG_CPA=CG_che/CG_at

*SG&A/TA
replace CG_xsga=0 if CG_xsga==.
gen CG_SGA_A=CG_xsga/CG_at

*ROA2
gen CG_ROA2=CG_oibdp/CG_at

*Asset tangibility
gen CG_PPE_A=CG_ppent/CG_at

*Investment/TA
gen CG_CAPX_A=CG_capx/CG_at

*Market to book equity ratio
gen CGD_MB=CGD_MV/CG_at if CG_curcd!="USD"
replace CGD_MB=CGD_MV_usd/CG_at if CG_curcd=="USD"
replace CGD_MB=CGD_MV_usd/CG_at_usd if CGD_MB==.
gen CGD_lnMB=ln(CGD_MB)

*Firm size
gen CG_lnTA=ln(CG_at)
gen CG_lnTA_usd=ln(CG_at_usd)
gen CG_lnSALE=ln(CG_sale)
gen CG_lnSALE_usd=ln(CG_sale_usd)
   
*Leverage
egen DEBT=rowtotal(CG_dlc CG_dltt)
replace DEBT=. if CG_dlc==. & CG_dltt==.
gen CEQ_1=-1*CG_ceq
egen deno_leverage=rowtotal(CG_at CEQ_1 CGD_MV)

gen CG_LEV_A=DEBT/CG_at
gen CG_LEV_MV=DEBT/deno_leverage

*Industry codes
gen CG_SIC4=real(CG_sic)
ffind CG_SIC4, newvar(CG_FF48) type(48)
ffind CG_SIC4, newvar(CG_FF12) type(12)
ffind CG_SIC4, newvar(CG_FF30) type(30)

*Cash flow
egen CG_CF=rowtotal(CG_ib CG_dp)
replace CG_CF=. if CG_ib==.
gen CG_CF_A=CG_CF/CG_at

label variable CG_CF_A "Cash flow/TA"

*Tobin's q
gen TX=-1*CG_txditc
replace TX=0 if TX==.
replace CG_pstk=0 if CG_pstk==.

gen CG_MVA=(CGD_MV+CG_lt+CG_pstk-TX)
gen CG_DIFF=CG_at-CG_ppent

gen CG_Q_A=(CG_MVA-CG_DIFF)/CG_at

sort gvkey2 CG_fyear
by gvkey2: gen CG_Q_A2=(CG_MVA-CG_DIFF)/CG_at[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1

label variable CG_Q_A "Tobin's q; source: Investment-cash flow sensitivity cannot be a good measure of financial constraints: Evidence from the time series"

*Whited and Wu's (2006) financial-constraint index
gen CG_SIC2=int(CG_SIC4/100)
gen CG_cyear=year(CG_datadate)
egen DIV3=rowtotal(CG_dvc CG_dvp)
gen DIV3_D=1 if DIV3>0 & DIV3!=.
replace DIV3_D=0 if DIV3_D==. & DIV3!=.

sort gvkey2 CG_fyear
by gvkey2: gen CG_SALE_G=(CG_sale-CG_sale[_n-1])/CG_sale[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
bys CG_SIC2 CG_cyear: egen AVG_SALE_G=mean(CG_SALE_G)

gen CG_WW=-0.091*(CG_CF/CG_at)-0.062*DIV3_D+0.021*(CG_dltt/CG_at)-0.044*(log(CG_at))+0.102*AVG_SALE_G-0.035*CG_SALE_G

label variable CG_WW "Whited and Wu's (2006) financial-constraint index"

*Taxes and NDTS
gen CG_TXT_A=CG_txt/CG_at
gen CG_NDTS_A=CG_dp/CG_at
replace CG_NDTS_A=0 if CG_NDTS_A==. & CG_at!=.

*Repurchase/TA
gen CG_REPUR_A=CG_prstkc/CG_at

*Total payout/TA
egen CG_TPAYOUT=rowtotal(CG_dvc CG_prstkc)
gen CG_TPAYOUT_A=CG_TPAYOUT/CG_at

*Equity issuance
egen CG_EIS=rowtotal(CG_sstk)
gen CG_EIS_A=CG_EIS/CG_at

*Prices
gen CGD_prc_usd=prcc_f/(DS_currency)
rename prcc_f CGD_prc
gen CGD_adjprc=CGD_prc/ajex
gen CGD_adjprc_usd=CGD_prc_usd/ajex
 
 sort gvkey2 CG_fyear
by gvkey2: gen CGD_ret12=((CGD_prc[_n]/ajex[_n])-(CGD_prc[_n-1]/ajex[_n-1]))/(CGD_prc[_n-1]/ajex[_n-1]) if CG_fyear[_n]==CG_fyear[_n-1]+1
by gvkey2: gen CGD_ret12_usd=((CGD_prc[_n]/(DS_currency[_n]*ajex[_n]))-(CGD_prc[_n-1]/(DS_currency[_n-1]*ajex[_n-1])))/(CGD_prc[_n-1]/(DS_currency[_n-1]*ajex[_n-1])) if CG_fyear[_n]==CG_fyear[_n-1]+1
 
 gen CGD_curcd=CG_curcd
rename ajex CGD_ajexdi

gen CG_isin=""
gen CG_sedol=""

keep gvkey2 CG_cusip8 DS_currency CG_acctstd CG_curcd CG_fyear CG_fyr CG_datadate CG_act CG_aqc CG_at CG_capx CG_ceq CG_che CG_cogs CG_cshr CG_dlc CG_dltis CG_dltr CG_dltt CG_dp CG_dvc CG_dvp CG_ebit CG_emp CG_ib CG_lct CG_lt CG_oibdp CG_ppent CG_prstkc CG_pstk CG_re CG_revt CG_sale CG_seq CG_sstk CG_teq CG_txditc CG_txt CG_wcap CG_xrd CG_xsga CG_exchg CG_isin CG_sedol CG_nicon CG_fic CG_naicsh CG_add1 CG_add2 CG_add3 CG_add4 CG_city CG_ggroup CG_gind CG_gsector CG_gsubind CG_idbflag CG_loc CG_prican CG_prirow CG_priusa CG_sic CG_ipodate CG_at_usd CG_seq_usd CG_teq_usd CG_sale_usd CG_cogs_usd CG_xsga_usd CG_RD_S CG_DIV_A CG_CPA CG_ROA2 CG_PPE_A CG_CAPX_A CG_lnTA CG_lnTA_usd CG_lnSALE CG_lnSALE_usd CG_LEV_A CG_SIC4 CG_FF48 CG_FF12 CG_FF30 CG_CF CG_CF_A CG_PPE CG_Q_A CG_SIC2 CG_cyear CG_WW CG_TXT_A CG_NDTS_A CG_REPUR_A CG_TPAYOUT CG_TPAYOUT_A CGD_curcd CGD_prc CGD_prc_usd CGD_MV CGD_MV_usd CGD_ajexdi CGD_adjprc CGD_adjprc_usd CGD_MB CGD_lnMB CGD_lnMV CGD_lnMV_usd CG_xint CG_EIS_A CGD_ret12 CGD_ret12_usd CGD_adjprc CGD_adjprc_usd CG_LEV_MV

order gvkey2 CG_cusip8 CG_fyear CG_cyear DS_currency CG_loc
  
sort gvkey2 CG_fyear
foreach var in CG_act CG_aqc CG_at CG_capx CG_ceq CG_che CG_cogs CG_cshr CG_dlc CG_dltis CG_dltr CG_dltt CG_dp CG_dvc CG_dvp CG_ebit CG_emp CG_ib CG_lct CG_lt CG_oibdp CG_ppent CG_prstkc CG_pstk CG_re CG_revt CG_sale CG_seq CG_sstk CG_teq CG_txditc CG_txt CG_wcap CG_xrd CG_xsga CG_nicon CG_at_usd CG_seq_usd CG_teq_usd CG_sale_usd CG_cogs_usd CG_xsga_usd CG_RD_S CG_DIV_A CG_CPA CG_ROA2 CG_PPE_A CG_CAPX_A CG_lnTA CG_lnTA_usd CG_lnSALE CG_lnSALE_usd CG_LEV_A CG_CF CG_CF_A CG_PPE CG_Q_A CG_WW CG_TXT_A CG_NDTS_A CG_REPUR_A CG_TPAYOUT CG_TPAYOUT_A CGD_prc CGD_prc_usd CGD_MV CGD_MV_usd CGD_cshocM CGD_adjprc CGD_adjprc_usd CGD_MB CGD_lnMB CGD_lnMV CGD_lnMV_usd CG_xint CG_EIS_A CGD_ret12 CGD_ret12_usd CGD_adjprc CGD_adjprc_usd CG_LEV_MV {
capture by gvkey2: gen l1_`var'=`var'[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
}

gen GLOBAL=0

save CompustatNAAnnualReady, replace


*********************************************
**#Append the Global and North American firms 
*********************************************
cd "$directory"
use CompustatGlobalReady, clear

append using CompustatNAAnnualReady

save AnnualReady, replace


************************************************************************************
**# Construct a linking tables for SEDOL (global firms) and 6-digit CUSIP (US firms)
************************************************************************************
*Global firms
cd "$directory"
use CompustatGlobalReady, clear

keep gvkey2 CG_sedol CG_SIC4 CG_fyear

drop if CG_sedol==""

collapse (last) gvkey2 CG_SIC4, by(CG_sedol)

save SEDOLReady, replace


*US firms
cd "$directory"
use CompustatNAFundamentalRaw1987_2021, clear

*Throughout, we use small letter for variable names
rename *, lower

gen gvkey2=real(gvkey)
gen CG_cusip6=substr(cusip,1,6)
gen CG_SIC4=real(sic)
rename fyear CG_fyear

keep gvkey2 CG_cusip6 CG_SIC4 CG_fyear

drop if CG_cusip6==""

collapse (last) gvkey2 CG_SIC4, by(CG_cusip6)

save CUSIP6Ready, replace


*************************************************************
**# Constructing the SDC M&A variables
* SDCM&ARaw1980_2024 contains all M&A deals from 1980 to 2024
*************************************************************
*Global firms
cd "$directory"
use SDCM&ARaw1980_2024 if ANATIONCODE!="US", clear

rename *, lower

rename aupsedol CG_sedol

*Filters
drop if CG_sedol==""
keep if apublic=="Public"
drop if deal_value==.
keep if status=="Completed"
drop if aup==tup & aup!="" 
keep if form=="Merger" | form=="Acq. of Assets" | form=="Acq. Maj. Int." 
keep if pctown>50 & pctown!=. & pctacq>=40 & pctacq!=.

*Merge using SEDOL to get their gvkey2 and SIC codes
merge m:1 CG_sedol using SEDOLReady
drop if _merge==2
drop _merge

gen CROSS=1 if anation!=tnation
replace CROSS=0 if anation==tnation

keep if CG_SIC4!=.
gen GLOBAL_SDC=1

save SDCGlobalReady, replace


*US firms
cd "$directory"
use SDCM&ARaw1980_2024 if ANATIONCODE=="US", clear

rename *, lower

*Filters
keep if apublic=="Public"
drop if deal_value==.
keep if status=="Completed"
drop if aup==tup & aup!="" 
keep if form=="Merger" | form=="Acq. of Assets" | form=="Acq. Maj. Int."  
keep if pctown>50 & pctown!=. & pctacq>=40 & pctacq!=.

*Merge to get gvkey2
rename aup CG_cusip6
drop if CG_cusip6==""
 
merge m:1 CG_cusip6 using CUSIP6Ready
drop if _merge==2
drop _merge

gen CROSS=1 if anation!=tnation
replace CROSS=0 if anation==tnation

keep if CG_SIC4!=.

gen GLOBAL_SDC=0

save SDCUSReady, replace


*************************************
*Append the Global and US M&A samples
*************************************
cd "$directory"
use SDCGlobalReady, clear

append using SDCUSReady

*SIC3 industry liquidity
gen CG_SIC3=int(CG_SIC4/10)
gen CG_TSIC3=int((real(tsicp))/10)

gen CG_SIC2=int(CG_SIC4/100)
gen CG_TSIC2=int((real(tsicp))/100)

drop if CG_TSIC2==.

*Total deal value
gen cyear=year(dateann)

*ISO 3 digit countries codes (ANATIONReady contains the 3-digit ISO country codes ("CG_loc") for each country ("anation") with acquirers; you could find the iso codes from here: https://www.iban.com/country-codes)
merge m:1 anation using ANATIONReady
drop if _merge==2
drop _merge

drop if CG_loc==""

*Compute total deal value for each country-industry-year bin
bys CG_SIC3 anationcode cyear: egen DealValue=sum(deal_value)

collapse (mean) DealValue, by (CG_SIC3 CG_loc cyear)

save DealValueReady, replace


***********************************************************
**# Construct a firm-year sample from the SDC deal sample
* To know if a firm has a acquisition deal in a year or not
***********************************************************
cd "$directory"
use SDCGlobalReady, clear

append using SDCUSReady

gen ACQUIRER=1
gen cyear=year(dateann)

keep gvkey2 cyear ACQUIRER
bys gvkey2 cyear: gen dup=_n
drop if dup>1
drop dup

save SDCAcquirerReady, replace


******************************************************
**# Construct deal-level samples for the target firms
******************************************************
*Global firms
cd "$directory"
use SDCM&ARaw1980_2024 if TNATIONCODE!="US", clear

rename *, lower

rename tupsedol CG_sedol

*Filters
drop if CG_sedol==""
drop if deal_value==.
keep if status=="Completed"
drop if aup==tup & aup!="" 
keep if form=="Merger" | form=="Acq. of Assets" | form=="Acq. Maj. Int."  
keep if pctown>50 & pctown!=. & pctacq>=40 & pctacq!=.
 
merge m:1 CG_sedol using SEDOLReady
drop if _merge==2
drop _merge

gen GLOBAL_SDC_TARGET=1
gen HOSTILE=1 if attitude=="Hostile"
replace HOSTILE=0 if HOSTILE==.

save SDCGlobalTargetReady, replace


*US firms
cd "$directory"
use SDCM&ARaw1980_2024 if TNATIONCODE=="US", clear

rename *, lower

*Filters
drop if deal_value==.
keep if status=="Completed"
drop if aup==tup & aup!="" 
keep if form=="Merger" | form=="Acq. of Assets" | form=="Acq. Maj. Int."  
keep if pctown>50 & pctown!=. & pctacq>=40 & pctacq!=.
 
rename tup CG_cusip6
drop if CG_cusip6==""

*Merge to get gvkey2
merge m:1 CG_cusip6 using CUSIP6Ready
drop if _merge==2
drop _merge

gen GLOBAL_SDC_TARGET=1
gen HOSTILE=1 if attitude=="Hostile"
replace HOSTILE=0 if HOSTILE==.

save SDCUSTargetReady, replace


*Append the Global and US target firms
cd "$directory"
use SDCGlobalTargetReady, clear

append using SDCUSTargetReady

gen TARGET=1
gen cyear=year(dateann)

drop if gvkey2==.

keep gvkey2 cyear TARGET HOSTILE
bys gvkey2 cyear: gen dup=_n
drop if dup>1
drop dup

save SDCTargetReady, replace


******************************************************
**# Estimating ROA volatility using quarterly earnings
******************************************************
*US firms
cd "$directory"
use CompustatMergedNAQuarterlyRaw, clear

rename *, lower
gen gvkey2=real(gvkey)

gen QROA1=ibq/atq

gen qdate=qofd(datadate)

bys gvkey2 qdate: gen dup=_n
drop if dup>1
drop dup

keep gvkey2 datadate qdate QROA1

save QROAVolNARaw, replace


*Global firms
cd "$directory"
use CompustatGlobalQuarterlyRaw, clear

rename *, lower
gen gvkey2=real(gvkey)

gen QROA1=ibq/atq

gen qdate=qofd(datadate)

bys gvkey2 qdate: gen dup=_n
drop if dup>1
drop dup

keep gvkey2 datadate qdate QROA1

append using QROAVolNARaw

save QROAVolRaw, replace


*Looping from qdate 120 to 253
forvalue i=120/253 {
local begin=`i'-11	

noisily display "ROA Vol qdate==`i'"

cd "$directory"
use QROAVolRaw if qdate>=`begin' & qdate<=`i', clear

keep if !missing(QROA1)
sort gvkey2 qdate

by gvkey2: gen OBS=_N

*Requiring at least 5 available observations
keep if OBS>=5

by gvkey2: egen CG_QROA1VOL=sd(QROA1)

collapse (mean) CG_QROA1VOL, by (gvkey2)

gen qdate=`i'

cd "$directory_qroavol"

local filename="QROAVOL_`i'"

save `filename', replace
}

*Append the temporary files into one panel
cd "$directory_qroavol"
use QROAVOL_120, clear

forvalue i=121/253 {
append using QROAVOL_`i'
}

cd "$directory"
save QROAVolReady, replace


******************************************************************************
*Adjust the time horizon forward so that
*t0 ROA vol is based quarterly estimation between quarter t and t+11
*t1 ROA vol is for year t+1 (estimated using quarter t+4 to t+15 
******************************************************************************
cd "$directory"
use QROAVolReady, clear

replace qdate=qdate-11

rename CG_QROA1VOL t0_CG_QROA1VOL

sort gvkey2 qdate
by gvkey2: gen t1_CG_QROA1VOL=t0_CG_QROA1VOL[_n+4] if qdate[_n]==qdate[_n+4]-4

save t1QROAVolReady, replace


*************************************************
**# Construct the Competition Law Index Variables
*************************************************
cd "$directory"
use CCL_CLI_Data_Ver2, clear

keep code_cowc country year cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm

rename code_cowc CG_loc
rename year cyear

drop if CG_loc=="NA"
replace CG_loc="AUS" if country=="Australia"
replace CG_loc="AUT" if country=="Austria"
replace CG_loc="BHR" if country=="Bahrain"
replace CG_loc="BGD" if country=="Bangladesh"
replace CG_loc="BWA" if country=="Botswana"
replace CG_loc="BGR" if country=="Bulgaria"
replace CG_loc="BFA" if country=="Burkina Faso"
replace CG_loc="CRI" if country=="Costa Rica"
replace CG_loc="HRV" if country=="Croatia"
replace CG_loc="CZE" if country=="Czech Republic"
replace CG_loc="DNK" if country=="Denmark"
replace CG_loc="FRA" if country=="France"
replace CG_loc="DEU" if country=="Germany"
replace CG_loc="HKG" if country=="Hong Kong"
replace CG_loc="ISL" if country=="Iceland"
replace CG_loc="IDN" if country=="Indonesia"
replace CG_loc="IRL" if country=="Ireland"
drop if country=="Korea"
replace CG_loc="KAZ" if country=="Kazakhstan"
replace CG_loc="KWT" if country=="Kuwait"
replace CG_loc="LVA" if country=="Latvia"
replace CG_loc="LBN" if country=="Lebanon"
replace CG_loc="LBY" if country=="Libya"
replace CG_loc="LTU" if country=="Lithuania"
replace CG_loc="MKD" if country=="Macedonia"
replace CG_loc="MDG" if country=="Madagascar"
replace CG_loc="MYS" if country=="Malaysia"
replace CG_loc="MDV" if country=="Maldives"
replace CG_loc="MCO" if country=="Monaco"
replace CG_loc="MAR" if country=="Morocco"
replace CG_loc="MMR" if country=="Myanmar"
replace CG_loc="NPL" if country=="Nepal"
replace CG_loc="NLD" if country=="Netherlands"
replace CG_loc="NZL" if country=="New Zealand"
replace CG_loc="NER" if country=="Niger"
replace CG_loc="NGA" if country=="Nigeria"
replace CG_loc="OMN" if country=="Oman"
replace CG_loc="PRY" if country=="Paraguay"
replace CG_loc="PHL" if country=="Philippines"
replace CG_loc="PRT" if country=="Portugal"
replace CG_loc="VNM" if country=="Republic of Vietnam"
replace CG_loc="SGP" if country=="Singapore"
replace CG_loc="SVK" if country=="Slovakia"
replace CG_loc="SVN" if country=="Slovenia"
replace CG_loc="ZAF" if country=="South Africa"
replace CG_loc="KOR" if country=="South Korea"
replace CG_loc="ESP" if country=="Spain"
replace CG_loc="LKA" if country=="Sri Lanka"
replace CG_loc="SWZ" if country=="Swaziland"
replace CG_loc="SWE" if country=="Sweden"
replace CG_loc="CHE" if country=="Switzerland"
replace CG_loc="TWN" if country=="Taiwan"
replace CG_loc="TJK" if country=="Tajikistan"
replace CG_loc="TZA" if country=="Tanzania"
replace CG_loc="THA" if country=="Thailand"
replace CG_loc="TTO" if country=="Trinidad and Tobago"
replace CG_loc="ARE" if country=="United Arab Emirates"
replace CG_loc="GBR" if country=="United Kingdom"
replace CG_loc="URY" if country=="Uruguay"
replace CG_loc="VNM" if country=="Vietnam"
replace CG_loc="SER" if country=="Yugoslavia"

*Remove duplicates within each country-year
sort CG_loc cyear cli_overall_norm
bys CG_loc cyear: gen dup=_n
keep if dup==1
drop dup

*Construct the variables in changes
sort CG_loc cyear
foreach var in cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm {
by CG_loc: gen chg_`var'=`var'[_n]-`var'[_n-1] if cyear[_n]==cyear[_n-1]+1
by CG_loc: gen l1_`var'=`var'[_n-1] if cyear[_n]==cyear[_n-1]+1
}

*Compute the change dummy variables (Up and Down)
gen cliUp=1 if chg_cli_overall_norm>0 & chg_cli_overall_norm!=.
replace cliUp=0 if cliUp==. & chg_cli_overall_norm!=.
gen cliDn=1 if chg_cli_overall_norm<0 & chg_cli_overall_norm!=.
replace cliDn=0 if cliDn==. & chg_cli_overall_norm!=.

foreach var in cliUp cliDn {
by CG_loc: gen t1_`var'=`var'[_n+1] if cyear[_n]==cyear[_n+1]-1
by CG_loc: gen t2_`var'=`var'[_n+2] if cyear[_n]==cyear[_n+2]-2
}

*Countries that never had a change
sort CG_loc cyear
by CG_loc: egen MEAN_chg_cli_overall_norm=mean(chg_cli_overall_norm)

gen NoCHG=1 if MEAN_chg_cli_overall_norm==0 
replace NoCHG=0 if NoCHG==.

save CLIReady, replace


*********************************
**# Merging All Datasets Together
*********************************
cd "$directory"
use AnnualReady, clear

gen cyear=CG_cyear

gen qdate=qofd(CG_datadate)

*Quarterly ROA1 vol
merge m:1 gvkey2 qdate using QROAVolReady
drop if _merge==2
drop _merge

sort gvkey2 CG_fyear
by gvkey2: gen l1_CG_QROA1VOL=CG_QROA1VOL[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1

*Quarterly t0 and t1 ROA1 vol
merge m:1 gvkey2 qdate using t1QROAVolReady
drop if _merge==2
drop _merge

*Country characteristics (WB_VAR_Ready is a country-year panel containing country characteristics from World Bank: You can download them from https://databank.worldbank.org/source/world-development-indicators)
merge m:1 CG_loc cyear using WB_VAR_Ready
drop if _merge==2
drop _merge

*Log-transform the country variables
gen l1_lnWB_GDPPC=ln(l1_WB_GDPPC)

*SIC3 industry classification
gen CG_SIC3=int(CG_SIC4/10)

*Industry competition HHI
*Lagged
bys CG_loc cyear CG_SIC3: egen TOTAL_SALE=sum(l1_CG_sale)
gen sale_r=(l1_CG_sale/TOTAL_SALE)^2
bys CG_loc cyear CG_SIC3: egen l1_CG_HHI_SIC3=sum(sale_r)
drop TOTAL_SALE sale_r

*Contemporaneous
bys CG_loc cyear CG_SIC3: egen TOTAL_SALE=sum(CG_sale)
gen sale_r=(CG_sale/TOTAL_SALE)^2
bys CG_loc cyear CG_SIC3: egen CG_HHI_SIC3=sum(sale_r)
drop TOTAL_SALE sale_r

*Shareholder rights index from Djankov et a. (2008): https://faculty.tuck.dartmouth.edu/rafael-laporta/research-publications
merge m:1 CG_loc using AntiDir
drop if _merge==2
drop _merge

*Merge with competition law index
merge m:1 CG_loc cyear using CLIReady
drop if _merge==2
drop _merge

*Merge with SDC variables
merge m:1 CG_SIC3 CG_loc cyear using DealValueReady
drop if _merge==2
drop _merge

bys CG_loc CG_SIC3 cyear: egen TOT_TA=sum(CG_at_usd)

sort gvkey2 CG_fyear
foreach var in DealValue {
replace `var'=0 if `var'==.
gen `var'_A=`var'/TOT_TA
by gvkey2: gen l1_`var'_A=`var'_A[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
}

*Acquirer firm-level
merge m:1 gvkey2 cyear using SDCAcquirerReady 
drop if _merge==2
drop _merge

replace ACQUIRER=0 if ACQUIRER==.

sort gvkey2 CG_fyear
by gvkey2: gen t1_ACQUIRER=ACQUIRER[_n+1] if CG_fyear[_n]==CG_fyear[_n+1]-1
by gvkey2: gen t2_ACQUIRER=ACQUIRER[_n+2] if CG_fyear[_n]==CG_fyear[_n+1]-1
by gvkey2: gen t3_ACQUIRER=ACQUIRER[_n+3] if CG_fyear[_n]==CG_fyear[_n+1]-1

*Target firm-level
merge m:1 gvkey2 cyear using SDCTargetReady
drop if _merge==2
drop _merge

replace TARGET=0 if TARGET==.

*Institutional Ownership (from FactSet Lionshares)
merge m:1 CG_isin qdate using GLOBALIOReady
drop if _merge==2
drop _merge

merge m:1 CG_cusip8 qdate using USIOReady
drop if _merge==2
drop _merge

egen IO=rowtotal(GLOBAL_io NA_io)
egen IO_DOM=rowtotal(GLOBAL_io_dom NA_io_dom)
egen IO_for=rowtotal(GLOBAL_io_for NA_io_for)

replace IO=. if GLOBAL_io==. & NA_io==.
replace IO_DOM=. if GLOBAL_io_dom==. & NA_io_dom==.
replace IO_for=. if GLOBAL_io_for==. & NA_io_for==.

egen l1_IO=rowtotal(l1_GLOBAL_io l1_NA_io)
egen l1_IO_DOM=rowtotal(l1_GLOBAL_io_dom l1_NA_io_dom)
egen l1_IO_for=rowtotal(l1_GLOBAL_io_for l1_NA_io_for)

replace l1_IO=. if l1_GLOBAL_io==. & l1_NA_io==.
replace l1_IO_DOM=. if l1_GLOBAL_io_dom==. & l1_NA_io_dom==.
replace l1_IO_for=. if l1_GLOBAL_io_for==. & l1_NA_io_for==.

*Number of firms per industry
bys CG_loc CG_SIC3 cyear: gen NoF_SIC3=_N

foreach var in NoF_SIC3 {
gen ln_`var'=ln(`var')
} 

*Lagged LEV_A
sort gvkey2 CG_fyear
by gvkey2: gen l2_CG_LEV_A=CG_LEV_A[_n-2] if CG_fyear[_n]==CG_fyear[_n-2]+2
by gvkey2: gen l3_CG_LEV_A=CG_LEV_A[_n-3] if CG_fyear[_n]==CG_fyear[_n-3]+3

*Forward LEV_A
by gvkey2: gen t1_CG_LEV_A=CG_LEV_A[_n+1] if CG_fyear[_n]==CG_fyear[_n+1]-1
by gvkey2: gen t2_CG_LEV_A=CG_LEV_A[_n+2] if CG_fyear[_n]==CG_fyear[_n+2]-2
by gvkey2: gen t3_CG_LEV_A=CG_LEV_A[_n+3] if CG_fyear[_n]==CG_fyear[_n+3]-3

*The main ZL measure
gen ZERO=1 if CG_LEV_A==0 
replace ZERO=0 if CG_LEV_A>0 & CG_LEV_A!=.

gen l1_ZERO=1 if l1_CG_LEV_A==0
replace l1_ZERO=0 if l1_CG_LEV_A>0 & l1_CG_LEV_A!=.

gen l2_ZERO=1 if l2_CG_LEV_A==0
replace l2_ZERO=0 if l2_CG_LEV_A>0 & l2_CG_LEV_A!=.

*The alternative ZL measure (book leverage<0.025)
gen ZERO25=1 if CG_LEV_A<0.025
replace ZERO25=0 if ZERO25==. & CG_LEV_A!=.

*Current and lagged dividend payer dummy
gen l1_CG_DIV_D=1 if l1_CG_DIV_A>0 & l1_CG_DIV_A!=.
replace l1_CG_DIV_D=0 if l1_CG_DIV_D==. & l1_CG_DIV_A!=.

gen CG_DIV_D=1 if CG_DIV_A>0 & CG_DIV_A!=.
replace CG_DIV_D=0 if CG_DIV_D==. & CG_DIV_A!=.

*Interest expenses
gen CG_XINT_A=CG_xint/CG_at
gen l1_CG_XINT_A=l1_CG_xint/l1_CG_at

egen DEBT=rowtotal(CG_dlc CG_dltt)
egen l1_DEBT=rowtotal(l1_CG_dlc l1_CG_dltt)

gen CG_XINT_D=CG_xint/DEBT
gen l1_CG_XINT_D=l1_CG_xint/l1_DEBT

drop DEBT l1_DEBT

*Industry groups variables
egen CG_gind2=group(CG_gind)
egen CG_ggroup2=group(CG_ggroup)

*Country group variable
egen CG_loc2=group(CG_loc)

tsset gvkey2 CG_fyear
sort gvkey2 CG_fyear

save FinalSample0, replace


*************************************************************************************************************************************
**#Exclusion criteria (here we arrive at the final sample)

*Note: In the pseudo dataset provided in the package, the final sample is renamed as "FinalSamplePseudo" instead of "FinalSample" in the codes below. 
*Please replace "FinalSample" with "FinalSamplePseudo".

*We have removed firm identifiers and replaced them with one pseudo firm id variable "pseudo_id".

*So, to run the codes below, please replace gvkey2 with pseudo_id. 

*Note also that since the number of industries and countries may have changed due to the pseudo sampling procedure, some analysis may not run properly, e.g., the matching tests and deleveraging-sample tests (or they need some adjustments in terms of the start and end years for the loops).

*************************************************************************************************************************************
cd "$directory"
use FinalSample0, clear

sort gvkey2 CG_fyear

*Exclusion criteria
drop if CG_SIC4>=6000 & CG_SIC4<=6999
drop if CG_gind==""
drop if CG_ggroup==""

keep if !missing(CG_LEV_A, cli_overall_norm, l1_CGD_lnMV_usd, l1_CGD_MB, l1_CG_RD_S, l1_CG_CAPX_A, l1_CG_PPE_A, l1_CG_CPA, l1_CG_ROA2, l1_CG_DIV_A, l1_CG_TXT_A, l1_CG_NDTS_A, l1_WB_RCPI, l1_WB_PriCred, l1_WB_RGDP, l1_lnWB_GDPPC, l1_WB_MktGDP, l1_WB_StTrGDP, CG_FF48)

*drop if a country has fewer than 10 firms
egen NoFirm=nvals(gvkey2), by(CG_loc)
drop if NoFirm<10

*Set up regions ("RegionReady" contains country 3-digit ISO code and their corresponding economic regions)
merge m:1 CG_loc using RegionReady
drop if _merge==2
drop _merge

egen region2=group(region)

*Missing REPUR and DIV treated as 0
replace CG_REPUR_A=0 if CG_REPUR_A==. & CG_DIV_A!=.
replace CG_DIV_A=0 if CG_DIV_A==. & CG_REPUR_A!=.
replace CG_TPAYOUT_A=. if CG_DIV_A==. & CG_REPUR_A==.

*Winsorization
foreach var in CG_LEV_A CG_DIV_A CG_REPUR_A CG_TPAYOUT_A CG_CPA cli_overall_norm CG_lnTA_usd CGD_MB CG_RD_S CG_CAPX_A CG_ROA2 WB_RCPI WB_PriCred WB_RGDP lnWB_GDPPC WB_MktGDP cli_authority_norm cli_substance_norm CG_HHI_SIC3 WB_StTrGDP CG_WW CG_Q_A CG_CF_A CG_PPE_A CG_TXT_A CG_NDTS_A CG_QROA1VOL CG_RD_A CGD_lnMV_usd CG_lnSALE_usd l1_CG_QROA1VOL t0_CG_QROA1VOL t1_CG_QROA1VOL DealValue DealValue_A CG_XINT_A CG_XINT_D IND_l1_CG_XINT_D IND_CG_XINT_D CG_EIS_A CGD_ret12_usd CG_LEV_MV {
capture winsor `var', gen(`var'_w) p(0.01)
capture winsor l1_`var', gen(l1_`var'_w) p(0.01)
}

save FinalSample, replace


******************************************************************************************
* This panel contains all countries analyzed in the final sample; used for syncing samples
******************************************************************************************
cd "$directory"
use FinalSample, clear

bys CG_loc: gen dup=_n
keep if dup==1
drop dup

keep CG_loc
gen CountrySample=1

save CountrySample, replace


*************************************************************************
**# TABLES 1 & 2 - Descriptive Statistics by Country + Summary statistics
*************************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"


*TABLE 1
*Number of observations per country
tab CG_loc

*Average ZL per country
tab CG_loc, sum(ZERO)

*Number of unique firms per country
bys gvkey2: gen dup=_n
drop if dup>1
drop dup

tab CG_loc

*Country-average CLI
cd "$directory"
use FinalSample, clear

collapse (mean) cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm, by (CG_loc cyear)
collapse (mean) cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm, by (CG_loc)

sum cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm


*TABLE 2
cd "$directory"
use FinalSample, clear

*Panel A - Firm-year level
*Summary statistics firm-year level
tabstat ZERO ZERO25 CG_LEV_A_w cli_overall_norm chg_cli_overall_norm l1_CGD_MV_usd $firm, stat(n mean sd p25 p50 p75) col(stat) 

*Panel B - Country-year level
collapse (mean) cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm $country, by (CG_loc cyear)
tabstat cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm $country, stat(n mean sd p25 p50 p75) col(stat) 




****************************************************************
**# TABLE 3 - Competition and ZL Policies (Baseline regressions)
****************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"

*Baseline
reghdfe ZERO cli_overall_norm, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab3_Baseline.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ZERO cli_overall_norm $firm, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab3_Baseline.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe ZERO cli_overall_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab3_Baseline.xls", ctitle((3)) dec(3) t(3) r2 append tstat




*************************************************************
**# TABLE 4 - Competition and ZL Policies: Component Analysis
*************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"

reghdfe ZERO cli_authority_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab4_Components.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ZERO cli_substance_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab4_Components.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe ZERO cli_authority_norm cli_substance_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab4_Components.xls", ctitle((3)) dec(3) t(3) r2 append tstat
reghdfe ZERO cli_authority_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab4_Components.xls", ctitle((4)) dec(3) t(3) r2 append tstat




*********************************************************
**# TABLE 5 - Competition and Future Cash-Flow Volatility 
*********************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_CPA_w l1_CG_ROA2_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_DIV_A_w l1_CG_PPE_A_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*Construct a percentile rank variable for ROA vol (0 to 1)
bys CG_loc CG_fyear: astile t1_QROAVOL_100=t1_CG_QROA1VOL, nq(100)
replace t1_QROAVOL_100=t1_QROAVOL_100/100 

sort gvkey2 CG_fyear

cd "$directory_results"

reghdfe t1_CG_QROA1VOL_w cli_overall_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab5_CFVol.xls", ctitle(ROAVOL) dec(4) t(3) r2 replace tstat
reghdfe d.t1_CG_QROA1VOL_w d.cli_overall_norm d.($firm $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "Tab5_CFVol.xls", ctitle(ROAVOL - Chg-on-Chg) dec(4) t(3) r2 append tstat

reghdfe t1_QROAVOL_100 cli_overall_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab5_CFVol.xls", ctitle(ROAVOL Rank) dec(3) t(3) r2 append tstat
reghdfe d.t1_QROAVOL_100 d.cli_overall_norm d.($firm $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "Tab5_CFVol.xls", ctitle(ROAVOL Rank - Chg-on-Chg) dec(3) t(3) r2 append tstat




***************************************************************
**# TABLE 6 - Competition and the Cash-Flow Sensitivity of Cash
***************************************************************
*Set up a new final sample for this analysis
cd "$directory"
use FinalSample0, clear

sort gvkey2 CG_fyear

by gvkey2: gen CHG_CPA_2=(CG_che[_n]-CG_che[_n-1])/CG_at if CG_fyear[_n]==CG_fyear[_n-1]+1

*Short debt
gen SDEBT=CG_dlc
by gvkey2: gen CHG_SDEBT=(SDEBT[_n]-SDEBT[_n-1])/CG_at if CG_fyear[_n]==CG_fyear[_n-1]+1

*NWC
gen NWC=(CG_act-CG_lct-CG_che)
sort gvkey2 CG_fyear
by gvkey2: gen CHG_NWC=(NWC[_n]-NWC[_n-1])/CG_at if CG_fyear[_n]==CG_fyear[_n-1]+1

*AQC
replace CG_aqc=0 if CG_aqc==. & CG_at!=.
gen CG_AQC_A=CG_aqc/CG_at
by gvkey2: gen l1_CG_AQC_A=CG_AQC_A[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1

*Merge with CLI
merge m:1 CG_loc cyear using CLIReady
drop if _merge==2
drop _merge

*Set up regions
merge m:1 CG_loc using RegionReady
drop if _merge==2
drop _merge

egen region2=group(region)

sort gvkey2 CG_fyear

*Exclusion criteria
drop if CG_SIC4>=6000 & CG_SIC4<=6999
drop if CG_gind==""
drop if CG_ggroup==""

keep if !missing(CHG_CPA_2, l1_CG_Q_A, CG_CF_A, l1_CG_lnTA_usd, l1_CG_CAPX_A, l1_CG_AQC_A, CHG_NWC, CHG_SDEBT, cli_overall_norm, l1_WB_RCPI, l1_WB_PriCred, l1_WB_RGDP, l1_lnWB_GDPPC, l1_WB_MktGDP, l1_WB_StTrGDP, CG_FF48)

*drop if a country has fewer than 10 firms
egen NoFirm=nvals(gvkey2), by(CG_loc)
drop if NoFirm<10

*Sync with the sample countries analyzed
merge m:1 CG_loc using CountrySample
keep if CountrySample==1
drop _merge

foreach var in CHG_CPA_2 CG_CF_A cli_overall_norm l1_WB_RCPI l1_WB_PriCred l1_WB_RGDP l1_lnWB_GDPPC l1_WB_MktGDP l1_WB_StTrGDP l1_CG_Q_A l1_CG_lnTA_usd l1_CG_CAPX_A l1_CG_AQC_A CHG_NWC CHG_SDEBT {
capture winsor `var', gen(`var'_w) p(0.01)
}

save FinalSample_CFSensitivity, replace


* Competition and Cash-Flow Sensitivity of Cash - Regressions
cd "$directory"
use FinalSample_CFSensitivity, clear

global firm_CFSensitivity "l1_CG_Q_A_w l1_CG_lnTA_usd_w l1_CG_CAPX_A_w l1_CG_AQC_A_w CHG_NWC_w CHG_SDEBT_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"

reghdfe CHG_CPA_2_w c.(CG_CF_A_w)##c.(cli_overall_norm) , absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab6_CashCF.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe CHG_CPA_2_w c.(CG_CF_A_w)##c.(cli_overall_norm) $firm_CFSensitivity, absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab6_CashCF.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe CHG_CPA_2_w c.(CG_CF_A_w)##c.(cli_overall_norm) $firm_CFSensitivity $country, absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab6_CashCF.xls", ctitle((3)) dec(3) t(3) r2 append tstat
reghdfe CHG_CPA_2_w c.(CG_CF_A_w)##c.(cli_overall_norm) $firm_CFSensitivity $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab6_CashCF.xls", ctitle((4)) dec(3) t(3) r2 append tstat




******************************************************************
**# TABLE 7 - Competition, Cash-Flow Volatilities, and ZL Policies 
******************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_CPA_w l1_CG_ROA2_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_DIV_A_w l1_CG_PPE_A_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*Construct a percentile rank variable for ROA vol (0 to 1)
bys CG_loc CG_fyear: astile l1_QROAVOL_100=l1_CG_QROA1VOL, nq(100)
replace l1_QROAVOL_100=l1_QROAVOL_100/100 

sort gvkey2 CG_fyear

cd "$directory_results"

reghdfe ZERO c.(cli_overall_norm)##c.l1_CG_QROA1VOL_w $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab7_ROAVOL.xls", ctitle(ROAVOL) dec(3) t(3) r2 replace tstat
reghdfe ZERO c.(cli_overall_norm)##c.l1_QROAVOL_100 $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab7_ROAVOL.xls", ctitle(ROAVOL rank variable) dec(3) t(3) r2 append tstat




*******************************************************************
**# TABLE 8 - Heterogeneity Tests According to Financial Constraint
*******************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_CPA_w l1_CG_ROA2_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_DIV_A_w l1_CG_PPE_A_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*WW index
bys CG_loc CG_fyear: astile WW_RANK=l1_CG_WW, nq(4)
gen WWUp=1 if WW_RANK>=3 & WW_RANK!=.
replace WWUp=0 if WWUp==. & WW_RANK!=.

*No dividend dummy
gen NoDIV=1-l1_CG_DIV_D

cd "$directory_results"

reghdfe ZERO c.(cli_overall_norm $firm $country)##c.NoDIV, absorb(gvkey2#NoDIV CG_FF48#CG_fyear#NoDIV) cluster(CG_loc) keepsingleton
outreg2 using "Tab8_FC.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ZERO c.(cli_overall_norm $firm $country)##c.WWUp, absorb(gvkey2#WWUp CG_FF48#CG_fyear#WWUp) cluster(CG_loc) keepsingleton
outreg2 using "Tab8_FC.xls", ctitle((2)) dec(3) t(3) r2 append tstat





******************************************************************************
**# TABLE 9 - Competition and Corporate Policies Surrounding ZL Events - SETUP
******************************************************************************
*Set up a new final sample; identify ZL events
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*Getting three years no ZERO and then 3 years ZERO
sort gvkey2 CG_fyear

by gvkey2: gen Z=1 if ZERO[_n]==1 & ZERO[_n+1]==1 & ZERO[_n+2]==1 & ZERO[_n-1]==0 & ZERO[_n-2]==0 & ZERO[_n-3]==0 & CG_fyear[_n+2]==CG_fyear[_n-3]+5
gen ZERO_fyear=CG_fyear if Z==1
by gvkey2: egen ZERO_fyear2=max(ZERO_fyear)

gen EVENTYR=CG_fyear-ZERO_fyear2
keep if (EVENTYR>=-3 & EVENTYR<=2) | EVENTYR==.
drop ZERO_fyear ZERO_fyear2

*Remove duplicates per gvkey-cyear (cyear is calendar year)
sort gvkey2 cyear CG_datadate
by gvkey2 cyear: gen dup=_n
keep if dup==1
drop dup

replace Z=0 if Z==.

*Estimate propensity scores using a full-sample logit regression
cd "$directory_results"

logit Z $firm $country i.CG_FF48 i.cyear, cluster(CG_loc)
outreg2 using "PreMatchLogit.xls", ctitle((1)) dec(3) t(3) r2 replace tstat

predict PSCORE, pr

cd "$directory"
save ZLEVENTSample, replace


**************************************************************
* Loop through each year with CLI changes; perform the matching
* Event window [-2, +3] - total 6 years
**************************************************************
forvalue i=1991/2008 {
local begin=`i'-3
local end=`i'+2
cd "$directory"
use ZLEVENTSample if cyear>=`begin' & cyear<=`end', clear

noisily display "year `i'"

sum Z if cyear==`i', d
if r(max)>0 & r(N)!=0 {

sort gvkey2 cyear

*Treatment dummy variable
gen TREAT2=1 if Z==1 & cyear==`i' 
by gvkey2: egen TREAT=mean(TREAT2)
replace TREAT=0 if TREAT==.
drop TREAT2

*Keep only `clean' control firms, i.e., remove all control that will be treated or already treated within the event window
by gvkey2: egen AVG=max(ZERO)
drop if TREAT==0 & AVG!=0
drop AVG

*Keep if data available in all 6 years in the event window
by gvkey2: gen NUM=_N
keep if NUM==6

*Post-period dummy variable
gen POST=1 if cyear>=`i'
replace POST=0 if cyear<`i'
gen PRE=1 if cyear<`i'

*Perform matching using the propensity scores estimated; Matching within country; 1:1 matching; No replacement; Caliber=0.01
gen double PSCORE2=PSCORE+CG_loc2*1000
psmatch2 TREAT if cyear==`i', pscore(PSCORE2) quiet noreplacement cal(0.01)

*Keep only the treated and matched control firms
sort gvkey2 cyear
by gvkey2: egen WEIGHT=max(_weight) 

keep if WEIGHT==1

gen PSM_EVENTYR=0 if cyear==`i'
replace PSM_EVENTYR=-1 if cyear==(`i'-1)
replace PSM_EVENTYR=-2 if cyear==(`i'-2)
replace PSM_EVENTYR=-3 if cyear==(`i'-3)
replace PSM_EVENTYR=1 if cyear==(`i'+1)
replace PSM_EVENTYR=2 if cyear==(`i'+2)

*Cohort year
gen COHORT=`i'

local filename="StackPSMEVENT`i'"

cd "$directory_ZLEvent"
save `filename', replace
}	
*This else is for no laws passed at all
else {	
}
}


*******************
*Append the cohorts
*******************
cd "$directory_ZLEvent"
use StackPSMEVENT1991, clear

forvalue i=1992/2008 {
capture append using StackPSMEVENT`i'
}

cd "$directory"
save StackedPSMEVENTReady, replace


*******************************************************************************************
**# TABLE 9 - Competition and Corporate Policies Surrounding ZL Events - ANALYSIS (PANEL A)
*******************************************************************************************
*Panel A - Event Analysis Surrounding ZL Events

cd "$directory"
use StackedPSMEVENTReady, clear

*Average firm policies surrounding the ZL events for both treated and matched control firms by EVENT YEAR
collapse (mean) CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w, by (PSM_EVENTYR TREAT)

sort TREAT PSM_EVENTYR

*Average firm policies surrounding the ZL events for both treated and matched control firms by PRE vs. POST
cd "$directory"
use StackedPSMEVENTReady, clear

collapse (mean) CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w, by (TREAT POST)


*Post Minus Pre - Difference and significance
cd "$directory"
use StackedPSMEVENTReady, clear

egen firm_cohort_id=group(gvkey2 COHORT)

cd "$directory_results"

foreach var in CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w {
reghdfe `var' POST if TREAT==1, noabsorb cluster(firm_cohort_id) keepsingleton
outreg2 using "ZLEvent_PostMinusPre.xls", ctitle(`var') dec(3) t(3) r2 append tstat
reghdfe `var' POST if TREAT==0, noabsorb cluster(firm_cohort_id) keepsingleton
outreg2 using "ZLEvent_PostMinusPre.xls", ctitle(`var') dec(3) t(3) r2 append tstat
}


*Difference-in-differences estimates
cd "$directory"
use StackedPSMEVENTReady, clear

egen firm_cohort_id=group(gvkey2 COHORT)

cd "$directory_results"

foreach var in CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w {
reghdfe `var' c.TREAT##c.POST, noabsorb cluster(firm_cohort_id) keepsingleton
outreg2 using "ZLEvent_DiD.xls", ctitle(`var') dec(3) t(3) r2 append tstat
}


****************************************************************************************
**# TABLE 9 - Competition and Corporate Policies Surrounding ZL Events - SETUP (PANEL B)
****************************************************************************************
*Set up a panel dataset for the treated and matched control firms separately (so that they can merged to each other to compute the abnormal policy change variables)

*Matched control firms
cd "$directory"
use StackedPSMEVENTReady, clear

replace CG_REPUR_A_w=0 if CG_REPUR_A_w==. & CG_DIV_A_w!=.
replace CG_DIV_A_w=0 if CG_DIV_A_w==. & CG_REPUR_A_w!=.

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

keep if TREAT==0

keep PSM_EVENTYR gvkey2 COHORT _id CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w 

*Variables for the matched control firms
foreach var in CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w  {
rename `var' CON_`var'
}

*_id of a firm to be renamed as _n1
rename _id _n1

sort gvkey2 COHORT PSM_EVENTYR 

by gvkey2 COHORT: gen _n1_2=_n1 if PSM_EVENTYR==0
rename _n1 _n1_old
by gvkey2 COHORT: egen _n1=max(_n1_2)
drop _n1_2 _n1_old

save StackedPSMEVENTReady_CONTROL, replace


*Treated firms
cd "$directory"
use StackedPSMEVENTReady, clear

replace CG_REPUR_A_w=0 if CG_REPUR_A_w==. & CG_DIV_A_w!=.
replace CG_DIV_A_w=0 if CG_DIV_A_w==. & CG_REPUR_A_w!=.

keep if TREAT==1

*Change ID
sort gvkey2 COHORT PSM_EVENTYR 

by gvkey2 COHORT: gen _id_2=_id if PSM_EVENTYR==0
rename _id _id_old
by gvkey2 COHORT: egen _id=max(_id_2)
drop _id_2 _id_old

*Retain the _n1 to be merged with the matched control sample (note: _n1 is the id of the matched firm)
sort gvkey2 COHORT PSM_EVENTYR 

by gvkey2 COHORT: gen _n1_2=_n1 if PSM_EVENTYR==0
rename _n1 _n1_old
by gvkey2 COHORT: egen _n1=max(_n1_2)
drop _n1_2

*Merge with the matched control firms
merge m:1 _n1 COHORT PSM_EVENTYR using StackedPSMEVENTReady_CONTROL
drop if _merge==2
drop _merge

sort _id COHORT PSM_EVENTYR

egen firm_cohort_id=group(gvkey2 COHORT)

sort firm_cohort_id PSM_EVENTYR

*Average policy variables for each firm for the Pre and Post periods
collapse (mean) cli_overall_norm CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w CON_CG_LEV_A_w CON_CG_CPA_w CON_CG_DIV_A_w CON_CG_REPUR_A_w CON_CG_EIS_A_w (first) $firm $country gvkey2 chg_cli_overall_norm _n1 _id COHORT CG_fyear CG_loc CG_FF48 region2, by (firm_cohort_id POST)

*Compute the post-minus-pre changes in the policy variables for each firm
sort firm_cohort_id POST
foreach var in CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w CON_CG_LEV_A_w CON_CG_CPA_w CON_CG_DIV_A_w CON_CG_REPUR_A_w CON_CG_EIS_A_w $firm $country {
by firm_cohort_id: gen chg_`var'=`var'[_n]-`var'[_n-1]
}

keep if POST==1

*Generate the abnormal policy change variables
foreach var in CG_LEV_A_w CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w  {
gen AB_chg_`var'=chg_`var'-chg_CON_`var'
}

save StackedPSMEVENTReadyDID, replace


*******************************************************************************************
**# TABLE 9 - Competition and Corporate Policies Surrounding ZL Events - ANALYSIS (PANEL B)
*******************************************************************************************
cd "$directory"
use StackedPSMEVENTReadyDID, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"

reghdfe AB_chg_CG_CPA_w chg_cli_overall_norm $firm $country, absorb(CG_FF48#COHORT) cluster(CG_loc)  keepsingleton
outreg2 using "Tab9_ZLEvent_ABChg.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe AB_chg_CG_DIV_A_w chg_cli_overall_norm $firm $country, absorb(CG_FF48#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "Tab9_ZLEvent_ABChg.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe AB_chg_CG_REPUR_A_w chg_cli_overall_norm $firm $country, absorb(CG_FF48#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "Tab9_ZLEvent_ABChg.xls", ctitle((3)) dec(3) t(3) r2 append tstat
reghdfe AB_chg_CG_EIS_A_w chg_cli_overall_norm $firm $country, absorb(CG_FF48#COHORT) cluster(CG_loc)  keepsingleton
outreg2 using "Tab9_ZLEvent_ABChg.xls", ctitle((4)) dec(3) t(3) r2 append tstat




***********************************************************************************************
**# TABLE 10 - Competition and the Timing of ZL: Evidence from a Deleveraging Subsample - SETUP
***********************************************************************************************
*Set up a deleveraging sample
cd "$directory"
use FinalSample0, clear

replace l1_CG_REPUR_A=0 if l1_CG_REPUR_A==. & l1_CG_DIV_A!=.
replace CG_REPUR_A=0 if CG_REPUR_A==. & CG_DIV_A!=.
replace CG_DIV_A=0 if CG_DIV_A==. & CG_REPUR_A!=.

merge m:1 CG_loc cyear using CLIReady
drop if _merge==2
drop _merge

merge m:1 CG_loc using RegionReady
drop if _merge==2
drop _merge

egen region2=group(region)

sort gvkey2 CG_fyear

*Construct annual changes variables
foreach var in l1_cli_overall_norm cli_overall_norm l1_CGD_lnMV_usd l1_CGD_MB l1_CG_CPA l1_CG_ROA2 l1_CG_RD_S l1_CG_CAPX_A l1_CG_DIV_A l1_CG_PPE_A l1_CG_TXT_A l1_CG_NDTS_A l1_WB_RCPI l1_WB_RGDP l1_lnWB_GDPPC l1_WB_PriCred l1_WB_StTrGDP l1_WB_MktGDP {
by gvkey2: gen CHG_`var'=`var'[_n]-`var'[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
}

*Find peak leverage
sort gvkey2 CG_LEV_A

by gvkey2: gen MAX=_N
by gvkey2: gen NUM=_n

gen PEAK=1 if MAX==NUM
drop MAX NUM

sort gvkey2 CG_fyear

by gvkey2: gen NUM=_n
gen PEAK_NUM=NUM if PEAK==1
by gvkey2: egen PEAK_NUM2=mean(PEAK_NUM)

*Drop firms where its peak leverage value is 0
gen PEAK_LEV_A=CG_LEV_A if PEAK==1
by gvkey2: egen PEAK_LEV_A2=mean(PEAK_LEV_A)

drop if PEAK_LEV_A2==0
drop PEAK_LEV_A
rename PEAK_LEV_A2 PEAK_LEV_A

gen EVENTYR=NUM-PEAK_NUM2

*Keep only the 10 years post-peak
keep if EVENTYR>=1 & EVENTYR<=10

*Identify the first time the firm goes ZL in the deleveraging sample
by gvkey2: egen ZERO_N=seq() if ZERO==1
gen ZERO_year=CG_fyear if ZERO_N==1
drop ZERO_N
by gvkey2: egen ZERO_year2=mean(ZERO_year)

*Drop observations after firms reach ZL
drop if CG_fyear>ZERO_year2 & ZERO_year2!=.
drop ZERO_year2 ZERO_year

*Exclusion criteria
drop if CG_SIC4>=6000 & CG_SIC4<=6999

keep if !missing(CHG_cli_overall_norm, CHG_l1_CGD_lnMV_usd, CHG_l1_CGD_MB, CHG_l1_CG_RD_S, CHG_l1_CG_CPA, CHG_l1_CG_ROA2, CHG_l1_CG_CAPX_A, CHG_l1_CG_DIV_A, CHG_l1_CG_PPE_A, CHG_l1_CG_TXT_A, CHG_l1_CG_NDTS_A, CHG_l1_WB_RCPI, CHG_l1_WB_PriCred, CHG_l1_WB_RGDP, CHG_l1_lnWB_GDPPC, CHG_l1_WB_MktGDP, CHG_l1_WB_StTrGDP)

*Sync with in-sample countries
merge m:1 CG_loc using CountrySample
keep if CountrySample==1

*Winsorization
foreach var in CHG_cli_overall_norm CHG_l1_CGD_lnMV_usd CHG_l1_CGD_MB CHG_l1_CG_RD_S CHG_l1_CG_CPA CHG_l1_CG_ROA2 CHG_l1_WB_RCPI CHG_l1_WB_PriCred CHG_l1_WB_RGDP CHG_l1_lnWB_GDPPC CHG_l1_lnWB_05GDPPC CHG_l1_WB_MktGDP CHG_cli_authority_norm CHG_cli_substance_norm CHG_l1_WB_StTrGDP CHG_l1_CG_CAPX_A CHG_l1_CG_DIV_A CHG_l1_CG_PPE_A CHG_l1_CG_TXT_A CHG_l1_CG_NDTS_A l1_CG_CPA CG_CPA l1_CG_DIV_A CG_DIV_A l1_CG_REPUR_A CG_REPUR_A CG_EIS_A l1_CG_EIS_A  {
capture winsor `var', gen(`var'_w) p(0.01)
}

tsset gvkey2 CG_fyear
sort gvkey2 CG_fyear

*Set survival analysis
stset EVENTYR, failure(ZERO) id(gvkey2)

save DeleverageSample, replace


**************************************************************************************************
**# TABLE 10 - Competition and the Timing of ZL: Evidence from a Deleveraging Subsample - ANALYSIS
**************************************************************************************************
cd "$directory"
use DeleverageSample, clear

global CHG_firm "CHG_l1_CGD_lnMV_usd_w CHG_l1_CGD_MB_w CHG_l1_CG_ROA2_w CHG_l1_CG_PPE_A_w CHG_l1_CG_DIV_A_w CHG_l1_CG_RD_S_w CHG_l1_CG_CAPX_A_w CHG_l1_CG_CPA_w CHG_l1_CG_TXT_A_w CHG_l1_CG_NDTS_A_w"
global CHG_country "CHG_l1_WB_RCPI_w CHG_l1_WB_RGDP_w CHG_l1_lnWB_GDPPC_w CHG_l1_WB_PriCred_w CHG_l1_WB_StTrGDP_w CHG_l1_WB_MktGDP_w"

cd "$directory_results"
stcox CHG_l1_cli_overall_norm $CHG_firm $CHG_country i.CG_FF48, cluster(CG_loc) nohr
outreg2 using "Tab10_Deleverage.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
stcox CHG_l1_cli_overall_norm $CHG_firm $CHG_country i.CG_loc2 i.CG_FF48, cluster(CG_loc) nohr
outreg2 using "Tab10_Deleverage.xls", ctitle((2)) dec(3) t(3) r2 append tstat



****************************************************************************************************************
**# TABLE 10 - Competition and the Timing of ZL: Evidence from a Deleveraging Subsample - Descriptive statistics
****************************************************************************************************************
*Panel A - Descriptive Statistics
cd "$directory"
use DeleverageSample, clear

sort gvkey2 CG_fyear
by gvkey2: egen ZERO_S=max(ZERO)

*1614 unique firms
keep if ZERO_S==1

*Beginning and end measures
collapse (first) BEG_CG_CPA_w=l1_CG_CPA_w BEG_CG_DIV_A_w=l1_CG_DIV_A_w BEG_CG_REPUR_A_w=l1_CG_REPUR_A_w  BEG_CG_EIS_A_w=l1_CG_EIS_A_w BEG_CG_fyear=CG_fyear BEG_cyear=cyear (last) END_CG_CPA_w=CG_CPA_w END_CG_DIV_A_w=CG_DIV_A_w END_CG_REPUR_A_w=CG_REPUR_A_w END_CG_EIS_A_w=CG_EIS_A_w CG_loc region CG_FF48 CG_SIC4 END_CG_fyear=CG_fyear END_cyear=cyear (mean) PEAK_LEV_A, by(gvkey2)

foreach var in CG_CPA_w CG_DIV_A_w CG_REPUR_A_w CG_EIS_A_w CG_fyear {
gen DIFF_`var'=END_`var'-BEG_`var'
}




*********************************************************
**# TABLE 11 - Competition, Cost of Debt, and ZL Policies
*********************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*Compute average Interest Expenses/Debt for each country-industry-year (excluding firms whose Interest Expenses/Debt is >=0.5); winsorize the measure
bys CG_loc CG_SIC3 CG_fyear: egen IND2_CG_XINT_D=mean(CG_XINT_D) if CG_XINT_D<0.5
bys CG_loc CG_SIC3 CG_fyear: egen IND_CG_XINT_D=mean(IND2_CG_XINT_D)
drop IND2_CG_XINT_D
winsor IND_CG_XINT_D, gen(IND_CG_XINT_D_w) p(0.01)


*Panel A - Competition and Cost of Debt
cd "$directory_results"

reghdfe CG_XINT_D_w cli_overall_norm $firm $country if CG_XINT_D<0.5, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_XINT.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
sort gvkey2 CG_fyear 
reghdfe d.CG_XINT_D_w d.cli_overall_norm d.($firm2 $country) if CG_XINT_D<0.5 | l1_CG_XINT_D<0.5, absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_XINT.xls", ctitle((2)) dec(3) t(3) r2 append tstat


*Panel B - Competition, Industry Cost of Debt, and ZL Policies

*Outputing the coefficients
cd "$directory_results"

reghdfe IND_CG_XINT_D_w cli_overall_norm $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_Meditation_Coef.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ZERO cli_overall_norm $firm $country if IND_CG_XINT_D_w!=., absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_Meditation_Coef.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe ZERO cli_overall_norm $firm IND_CG_XINT_D_w $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_Meditation_Coef.xls", ctitle((3)) dec(3) t(3) r2 append tstat

*Outputing the standard errors
cd "$directory_results"

reghdfe IND_CG_XINT_D_w cli_overall_norm $firm $country if IND_CG_XINT_D_w!=., absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_Meditation_SE.xls", ctitle((1)) dec(5) sdec(5) r2 replace sideway stats(coef se) noaster noparen 
reghdfe ZERO cli_overall_norm $firm  $country if IND_CG_XINT_D_w!=., absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_Meditation_SE.xls", ctitle((2)) dec(5) sdec(5) r2 append sideway stats(coef se) noaster noparen 
reghdfe ZERO cli_overall_norm $firm IND_CG_XINT_D_w $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab11_Meditation_SE.xls", ctitle((3)) dec(5) sdec(5) r2 append sideway stats(coef se) noaster noparen 




*************************************
**# TABLE 12 - Competition and Payout
*************************************
cd "$directory"
use FinalSample, clear

*Firm controls excluded Dividend/TA
global firm3 "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_CPA_w l1_CG_ROA2_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_PPE_A_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

sort gvkey2 CG_fyear

cd "$directory_results"

reghdfe CG_REPUR_A_w cli_overall_norm $firm3 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab12_REPUR.xls", ctitle(Repur/TA) dec(3) t(3) r2 replace tstat
reghdfe d.CG_REPUR_A_w d.(cli_overall_norm $firm3 $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab12_REPUR.xls", ctitle(Changes in Repur/TA) dec(3) t(3) r2 append tstat




**************************************************************
**# TABLE 13 - Financial Flexibility and Managerial Quiet Life
**************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_CPA_w l1_CG_ROA2_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_DIV_A_w l1_CG_PPE_A_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"


*Shareholder rights index
reghdfe ZERO c.(cli_overall_norm)##c.antidir $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab13_QuietLife.xls", ctitle(Shareholder rights index) dec(3) t(3) r2 replace tstat

*Estimate the expected probabiltiy for being a M&A target
probit TARGET l1_CG_LEV_MV_w l1_CGD_ret12_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_DealValue_A_w l1_CG_HHI_SIC3_w i.CG_loc2 i.CG_FF48 i.CG_fyear, cluster(gvkey2)
predict PROB if e(sample), pr

*Estimate the distribution of the probability in bins
gen BIN=.

forvalue i=1/38 {
local j=`i'/100
local g=(`i'-1)/100

replace BIN=`i' if PROB>=`g' & PROB<`j'
}

sort gvkey2 CG_fyear

by gvkey2: gen l1_PROB=PROB[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1

*The probability in my sample is 0.062374
gen PROBUp=1 if l1_PROB>0.062374 & l1_PROB!=.
replace PROBUp=0 if PROBUp==. & l1_PROB!=.

reghdfe ZERO c.(cli_overall_norm)##c.PROBUp $firm $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab13_QuietLife.xls", ctitle(Expected target) dec(3) t(3) r2 append tstat


*Institutional ownership
winsor l1_IO, gen(l1_IO_w) p(0.01)

reghdfe ZERO c.(cli_overall_norm)##c.l1_IO_w $firm $country if CG_fyear>=2000, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "Tab13_QuietLife.xls", ctitle(IO) dec(3) t(3) r2 append tstat




******************************************
**# Online Appendix A - Correlation Matrix
******************************************
cd "$directory"
use FinalSample, clear

*Panel A - Firm-year level
pwcorr ZERO ZERO25 CG_LEV_A_w cli_overall_norm chg_cli_overall_norm $firm2, sig

*Panel B - Country-year level
collapse (mean) cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm $country, by (CG_loc cyear)
pwcorr cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm $country, sig




****************************************
**# Online Appendix B - Robustness tests
****************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"


*Alternative ZL
reghdfe ZERO25 cli_overall_norm $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(ZERO 2.5%) dec(3) t(3) r2 replace tstat

*Alternative industry FE
reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_SIC3#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(SIC3) dec(3) t(3) r2 append tstat

reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_gind2#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(GIND) dec(3) t(3) r2 append tstat

reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_ggroup2#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(GGROUP) dec(3) t(3) r2 append tstat

*Control for Region*Year FE
reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear region2#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(Region*Year FE) dec(3) t(3) r2 append tstat

*Control for Region*FF48*Year FE
reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_FF48#region2#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(Region*FF48*Year FE) dec(3) t(3) r2 append tstat

*Alternative clustering
reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc CG_fyear) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(Country+Year) dec(3) t(3) r2 append tstat

reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(gvkey2 CG_fyear) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(Firm clustering) dec(3) t(3) r2 append tstat

egen ind_loc=group(CG_FF48 CG_loc)
reghdfe ZERO cli_overall_norm $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(ind_loc CG_fyear) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(Firm clustering) dec(3) t(3) r2 append tstat

*Dropping US
reghdfe ZERO cli_overall_norm $firm2 $country if CG_loc!="USA", absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(non US) dec(3) t(3) r2 append tstat

*At least some changes in competition law countries
reghdfe ZERO cli_overall_norm $firm2 $country if MEAN_chg_cli_overall_norm>0, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAB_Robust.xls", ctitle(at least some changes) dec(3) t(3) r2 append tstat





*******************************************************************************************
**# Online Appendix C - The Inclusion Criterion (Competition Laws and Industry Competition)
*******************************************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

collapse (mean) ZERO CG_HHI_SIC3 NoF_SIC3 ln_NoF_SIC3 CG_ROA2 $firm $country l1_cli_overall_norm (last) region region2, by (CG_SIC3 CG_loc cyear)

winsor CG_HHI_SIC3, gen(CG_HHI_SIC3_w) p(0.01)
gen ln_CG_HHI_SIC3=ln(CG_HHI_SIC3_w)
winsor ln_CG_HHI_SIC3, gen(ln_CG_HHI_SIC3_w) p(0.01)
winsor ln_NoF_SIC3, gen(ln_NoF_SIC3_w) p(0.01)

egen SIC3_loc=group(CG_SIC3 CG_loc)

tsset SIC3_loc cyear
sort SIC3_loc cyear

egen CG_loc2=group(CG_loc)

cd "$directory_results"

*HHI
reghdfe ln_CG_HHI_SIC3_w l1_cli_overall_norm, absorb(CG_SIC3 CG_loc2 cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ln_CG_HHI_SIC3_w l1_cli_overall_norm $firm, absorb(CG_SIC3 CG_loc2 cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe ln_CG_HHI_SIC3_w l1_cli_overall_norm $firm $country, absorb(CG_SIC3 CG_loc2 cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((3)) dec(3) t(3) r2 append tstat
reghdfe ln_CG_HHI_SIC3_w l1_cli_overall_norm $firm $country, absorb(CG_loc2 CG_SIC3#cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((4)) dec(3) t(3) r2 append tstat

reghdfe ln_NoF_SIC3_w l1_cli_overall_norm, absorb(CG_SIC3 CG_loc2 cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((5)) dec(3) t(3) r2 append tstat
reghdfe ln_NoF_SIC3_w l1_cli_overall_norm $firm, absorb(CG_SIC3 CG_loc2 cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((6)) dec(3) t(3) r2 append tstat
reghdfe ln_NoF_SIC3_w l1_cli_overall_norm $firm $country, absorb(CG_SIC3 CG_loc2 cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((7)) dec(3) t(3) r2 append tstat
reghdfe ln_NoF_SIC3_w l1_cli_overall_norm $firm $country, absorb(CG_loc2 CG_SIC3#cyear) cluster(CG_loc) keepsingleton
outreg2 using "OAC_Inclusion.xls", ctitle((8)) dec(3) t(3) r2 append tstat




*************************************************************************************************
**# Online Appendix D - Pre-Existing ZL and Competition Laws - Estimating Expected ZL Probability
*************************************************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*Estimate the expected probabiltiy of having a ZL
probit ZERO $firm2 i.CG_FF48 i.CG_loc2 i.CG_fyear, cluster(CG_loc) 
predict E_ZERO if e(sample), pr

keep gvkey2 CG_fyear E_ZERO

sort gvkey2 CG_fyear
by gvkey2: gen l1_E_ZERO=E_ZERO[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1
by gvkey2: gen l2_E_ZERO=E_ZERO[_n-2] if CG_fyear[_n]==CG_fyear[_n-2]+2

save EZEROReady, replace


**********************************************************************************************
**# Online Appendix D - Pre-Existing ZL and Competition Laws - Set up a new country-year panel
**********************************************************************************************
cd "$directory"
use FinalSample0, clear

merge m:1 CG_loc cyear using CLIReady
drop if _merge==2
drop _merge

*Expected ZERO
merge m:1 gvkey2 CG_fyear using EZEROReady
drop if _merge==2
drop _merge

*Region
merge m:1 CG_loc using RegionReady
drop if _merge==2
drop _merge

egen region2=group(region)

*Exclusion criteria
drop if CG_SIC4>=6000 & CG_SIC4<=6999

collapse (mean) l1_CGD_lnMV_usd l1_CGD_MB l1_CG_ROA2 l1_CG_PPE_A l1_CG_DIV_A l1_CG_RD_S l1_CG_CAPX_A l1_CG_CPA l1_CG_TXT_A l1_CG_NDTS_A l1_ZERO l2_ZERO l1_E_ZERO l2_E_ZERO (last) l1_WB_RCPI l1_WB_RGDP l1_lnWB_GDPPC l1_WB_PriCred l1_WB_StTrGDP l1_WB_MktGDP cli_overall_norm cli_authority_norm cli_substance_norm cli_mergers_norm cli_dominance_norm cli_anticomp_norm, by (CG_loc cyear)

keep if !missing(l1_CGD_lnMV_usd, l1_CGD_MB, l1_CG_ROA2, l1_CG_PPE_A, l1_CG_DIV_A, l1_CG_RD_S, l1_CG_CAPX_A, l1_CG_CPA, l1_CG_TXT_A, l1_CG_NDTS_A, l1_ZERO, l2_ZERO, l1_E_ZERO, l2_E_ZERO, l1_WB_RCPI, l1_WB_RGDP, l1_lnWB_GDPPC, l1_WB_PriCred, l1_WB_StTrGDP, l1_WB_MktGDP, cli_overall_norm)

foreach var in l1_CGD_lnMV_usd l1_CGD_MB l1_CG_ROA2 l1_CG_PPE_A l1_CG_RD_S l1_CG_CAPX_A l1_CG_CPA l1_CG_DIV_A l1_CG_TXT_A l1_CG_NDTS_A l1_WB_RCPI l1_WB_RGDP l1_lnWB_GDPPC l1_WB_PriCred l1_WB_StTrGDP l1_WB_MktGDP {
winsor `var', gen(`var'_w) p(0.01)
}

*Sync with the in-sample countries
merge m:1 CG_loc using CountrySample
drop if _merge==2
drop _merge

keep if CountrySample==1

save PreExistingCountryPanel, replace


**************************************************************************
**# Online Appendix D - Pre-Existing ZL and Competition Laws - Regressions
**************************************************************************
cd "$directory"
use PreExistingCountryPanel, clear

global Pfirm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global Pcountry "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"

reghdfe cli_overall_norm l1_ZERO l2_ZERO $Pfirm $Pcountry, absorb(CG_loc cyear) cluster(CG_loc)
outreg2 using "OAD_Preexisting.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe cli_overall_norm l1_E_ZERO l2_E_ZERO $Pfirm $Pcountry, absorb(CG_loc cyear) cluster(CG_loc)
outreg2 using "OAD_Preexisting.xls", ctitle((2)) dec(3) t(3) r2 append tstat




****************************************************
**# Online Appendix E - Change-On-Change Regressions
****************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

*Change dummy - lead and lag
gen CLI=cliUp-cliDn
gen t1_CLI=t1_cliUp-t1_cliDn
gen t2_CLI=t2_cliUp-t2_cliDn

sort gvkey2 CG_fyear

*Make the down dummy to take on positive values instead (for a wald test of coefficient equality)
gen cliDn2=cliDn*-1


cd "$directory_results"

reghdfe d.ZERO d.cli_overall_norm d.($firm $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "OAE_ChgOnChg.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe d.ZERO CLI d.($firm $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "OAE_ChgOnChg.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe d.ZERO CLI d.($firm $country), absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "OAE_ChgOnChg.xls", ctitle((3)) dec(3) t(3) r2 append tstat
reghdfe d.ZERO cliUp cliDn2 d.($firm $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "OAE_ChgOnChg.xls", ctitle((4)) dec(3) t(3) r2 append tstat
test cliUp=cliDn2
reghdfe d.ZERO t2_CLI t1_CLI CLI d.($firm $country), absorb(CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton 
outreg2 using "OAE_ChgOnChg.xls", ctitle((5)) dec(3) t(3) r2 append tstat




******************************************************************************************
**# Online Appendix F - Alternative Stacked and Matching Approaches - Set up stacked panel
******************************************************************************************
*Stacked panel
forvalue i=1989/2010 {
local begin=`i'-3
local end=`i'+3
cd "$directory"
use FinalSample if cyear>=`begin' & cyear<=`end', clear

noisily display "cyear `i'"

sum chg_cli_overall_norm if cyear==`i', d
if r(max)>0 & r(N)!=0 {

sort gvkey2 CG_fyear

*Generate Treat
gen TREAT2=1 if chg_cli_overall_norm!=0 & chg_cli_overall_norm!=. & cyear==`i'
by gvkey2: egen TREAT=mean(TREAT2)
replace TREAT=0 if TREAT==.
drop TREAT2

*Remove control firms that will be treated or already treated
by gvkey2: egen AVG=mean(chg_cli_overall_norm)
drop if TREAT==0 & AVG!=0
drop AVG

*Post-period dummy variable
gen POST=1 if cyear>=`i'
replace POST=0 if cyear<`i'
gen PRE=1 if cyear<`i'

*Minimum 1 years before and 1 year after
by gvkey2: egen NUM_POST=sum(POST)
by gvkey2: egen NUM_PRE=sum(PRE)
drop PRE

keep if NUM_POST>=1 & NUM_PRE>=1

gen COHORT=`i'

local filename="StackRaw`i'"

cd "$directory_stacked"
save `filename', replace
}	
*This else is for no laws passed at all
else {	
}
}


*Append the cohorts
cd "$directory_stacked"
use StackRaw1992, clear

forvalue i=1993/2010 {
capture append using StackRaw`i'
}

cd "$directory"
save StackRawReady, replace


*******************************************************************************************************
**# Online Appendix F - Alternative Stacked and Matching Approaches - Regressions on the stacked sample
*******************************************************************************************************
cd "$directory"
use StackRawReady, replace

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"


cd "$directory_results"

reghdfe ZERO cli_overall_norm, absorb(gvkey2#COHORT CG_FF48#CG_fyear#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "OAF_Stacked.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ZERO cli_overall_norm $firm, absorb(gvkey2#COHORT CG_FF48#CG_fyear#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "OAF_Stacked.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe ZERO cli_overall_norm $firm $country, absorb(gvkey2#COHORT CG_FF48#CG_fyear#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "OAF_Stacked.xls", ctitle((3)) dec(3) t(3) r2 append tstat




****************************************************************************************************
**# Online Appendix F - Alternative Stacked and Matching Approaches - Set up stacked + matched panel
****************************************************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

gen CLI=cliUp-cliDn
gen CLI_D=1 if CLI!=0 & CLI!=.
replace CLI_D=0 if CLI_D==. & CLI!=.

cd "$directory_results"
logit CLI_D $firm $country i.CG_FF48 i.cyear, cluster(CG_loc)
outreg2 using "PreMatchLogit_OAF.xls", ctitle((1)) dec(3) t(3) r2 replace tstat

predict PSCORE, pr

cd "$directory"
save StackedPSM0, replace


*********
*Matching
*********
forvalue i=1989/2010 {
local begin=`i'-3
local end=`i'+3
cd "$directory"
use StackedPSM0 if cyear>=`begin' & cyear<=`end', clear

noisily display "year `i'"

sum chg_cli_overall_norm if cyear==`i', d
if r(max)>0 & r(N)!=0 {

sort gvkey2 cyear

*Treatment dummy variable
gen TREAT2=1 if chg_cli_overall_norm!=0 & chg_cli_overall_norm!=. & cyear==`i' 
by gvkey2: egen TREAT=mean(TREAT2)
replace TREAT=0 if TREAT==.
drop TREAT2

*Remove control firms that will be treated or already treated
by gvkey2: egen AVG=mean(chg_cli_overall_norm)
drop if TREAT==0 & AVG!=0
drop AVG

*Post-period dummy variable
gen POST=1 if cyear>=`i'
replace POST=0 if cyear<`i'
gen PRE=1 if cyear<`i'

gen T=1 if cyear==`i'

*Keep if at least 1 year before and 1 year after
by gvkey2: egen NUM_POST=sum(POST)
by gvkey2: egen NUM_PRE=sum(PRE)
by gvkey2: egen NUM_T=sum(T)
drop PRE

keep if NUM_POST>=1 & NUM_PRE>=1 & NUM_T==1

*PSM matching within the same economic region and the closest propensity scores
gen double PSCORE2=PSCORE+region2*100
psmatch2 TREAT if cyear==`i', pscore(PSCORE2) quiet noreplacement cal(0.01)

sort gvkey2 cyear
by gvkey2: egen WEIGHT=max(_weight) 

keep if WEIGHT==1

gen PSM_EVENTYR=0 if cyear==`i'
replace PSM_EVENTYR=-1 if cyear==(`i'-1)
replace PSM_EVENTYR=-2 if cyear==(`i'-2)
replace PSM_EVENTYR=-3 if cyear==(`i'-3)
replace PSM_EVENTYR=1 if cyear==(`i'+1)
replace PSM_EVENTYR=2 if cyear==(`i'+2)
replace PSM_EVENTYR=3 if cyear==(`i'+3)

gen COHORT=`i'

local filename="StackPSM`i'"

cd "$directory_stackedPSM"
save `filename', replace
}	
*This else is for no laws passed at all
else {	
}
}

***********
*Append all
***********
cd "$directory_stackedPSM"
use StackPSM1992, clear

forvalue i=1993/2010 {
capture append using StackPSM`i'
}

cd "$directory"
save StackPSMReady, replace


*****************************************************************************************
**# Online Appendix F - Alternative Stacked and Matching Approaches - Stacked Matched DiD
*****************************************************************************************
cd "$directory"
use StackPSMReady, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"

reghdfe ZERO cli_overall_norm, absorb(gvkey2#COHORT CG_FF48#CG_fyear#COHORT) cluster(CG_loc COHORT) keepsingleton
outreg2 using "OAF_StackedPSMDiD.xls", ctitle((1)) dec(3) t(3) r2 replace tstat
reghdfe ZERO cli_overall_norm $firm, absorb(gvkey2#COHORT CG_FF48#CG_fyear#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "OAF_StackedPSMDiD.xls", ctitle((2)) dec(3) t(3) r2 append tstat
reghdfe ZERO cli_overall_norm $firm $country, absorb(gvkey2#COHORT CG_FF48#CG_fyear#COHORT) cluster(CG_loc) keepsingleton
outreg2 using "OAF_StackedPSMDiD.xls", ctitle((3)) dec(3) t(3) r2 append tstat



*******************************************************************************************************
**# Online Appendix F - Alternative Stacked and Matching Approaches - Stacked Matched DiD - diagnostics
*******************************************************************************************************
cd "$directory"
use StackPSMReady, clear

gen l1_chg_ZERO=l1_ZERO-l2_ZERO

tabstat l1_chg_ZERO l1_ZERO $firm2 $country if TREAT==0 & PSM_EVENTYR==0, stat(mean var) col(stat) 

cd "$directory_results"

*Two sample T-tests 
foreach var in l1_chg_ZERO l1_ZERO $firm $country {
reghdfe `var' TREAT if PSM_EVENTYR==0, noabsorb cluster(CG_loc)
outreg2 using "OAF_TTEST.xls", ctitle(`var') dec(4) t(3) r2 append tstat
}





**********************************************************************************
**# Online Appendix G - Alternative Explanation: Mergers & Acquisitions Incentives
**********************************************************************************
cd "$directory"
use FinalSample, clear

global firm "l1_CGD_lnMV_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_CG_PPE_A_w l1_CG_DIV_A_w l1_CG_RD_S_w l1_CG_CAPX_A_w l1_CG_CPA_w l1_CG_TXT_A_w l1_CG_NDTS_A_w"
global country "l1_WB_RCPI_w l1_WB_RGDP_w l1_lnWB_GDPPC_w l1_WB_PriCred_w l1_WB_StTrGDP_w l1_WB_MktGDP_w"

cd "$directory_results"


*Panel A -  Excluding Acquiring Firms

reghdfe ZERO cli_overall_norm $firm $country if ACQUIRER==0, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAG_ExcAcquirers.xls", ctitle(No M&A t=0) dec(3) t(3) r2 replace tstat
reghdfe ZERO cli_overall_norm $firm $country if ACQUIRER==0 & t1_ACQUIRER==0 & t2_ACQUIRER==0 , absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAG_ExcAcquirers.xls", ctitle(No M&As t=0-2) dec(3) t(3) r2 append tstat


*Panel B - Competition, Propensity to Acquire, and ZL

*Deak value/TA
reghdfe ZERO c.(cli_overall_norm)##c.(l1_DealValue_A_w) $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAG_PropAcquire.xls", ctitle(Industry deal value) dec(3) t(3) r2 replace tstat

*Expected probability to acquire
probit ACQUIRER l1_CG_LEV_MV_w l1_CGD_ret12_usd_w l1_CGD_MB_w l1_CG_ROA2_w l1_DealValue_A_w l1_CG_HHI_SIC3_w i.CG_loc2 i.CG_FF48 i.CG_fyear, cluster(gvkey2)
predict PROB if e(sample), pr

*Estimate the distribution by bins
gen BIN=.

forvalue i=1/58 {
local j=`i'/100
local g=(`i'-1)/100

replace BIN=`i' if PROB>=`g' & PROB<`j'
}

sort gvkey2 CG_fyear

by gvkey2: gen l1_PROB=PROB[_n-1] if CG_fyear[_n]==CG_fyear[_n-1]+1

gen PROBUp=1 if l1_PROB>0.111376 & l1_PROB!=.
replace PROBUp=0 if PROBUp==. & l1_PROB!=.

reghdfe ZERO (c.cli_overall_norm##c.PROBUp) $firm2 $country, absorb(gvkey2 CG_FF48#CG_fyear) cluster(CG_loc) keepsingleton
outreg2 using "OAG_PropAcquire.xls", ctitle(Expected acquirer) dec(3) t(3) r2 append tstat




*The END**********************************************************************
